from base.base import Base
from loctors.addUserLoctors import *
from time import sleep
import allure


@allure.feature("CRMEB-用户分组")
class AddPage(Base):
    @allure.step("输入账号：{text}")
    def inputUser(self,text):
        self.input_texts(*user_pwd,0,text)
    @allure.step("输入密码：{text}")
    def inputPwd(self,text):
        self.input_texts(*user_pwd,1,text)
    @allure.step("点击登录按钮")
    def clickLoginBtn(self):
        self.click_element(*login_btn)
        sleep(3)
    @allure.step("点击用户")
    def clickUserBtn(self):
        self.click_elements(*userIcon,0)
    @allure.step("点击用户分组")
    def clickUserGroup(self):
        sleep(2)
        self.click_element(*userGroup)
    @allure.step("点击添加分组")
    def clickAddUserGroup(self):
        self.click_element(*addUserGroupIcon)
        sleep(2)
    @allure.step("输入用户分组名称：{text}")
    def inputUserGroup(self,text):
        self.input_texts(*inputGroup,2,text)
    @allure.step("点击弹窗中二次确认")
    def clickAcceptBtn(self):
        self.click_elements(*accept,-1)
        sleep(2)
    @allure.step("断言是否添加：{text} 成功")
    def assertText(self,text):
        texts = self.get_text(*("xpath",f"//*[text()='{text}']"))
        assert texts == text
    @allure.step("删除用户分组")
    def delGroup(self):
        self.click_elements(*delUserGroupIcon,-1)
        sleep(2)
        self.click_elements(*accept,-1)
        # 使用d1对象查数据库，看到底删除成功没有
    @allure.step("判断：删除{text} ")
    def delAssert(self,text):
        from common.databases import d1
        result = d1.searchOne(f"select * from eb_user_group where group_name='{text}'")
        if result is None:
            pass
        else:
            raise "未删除成功"


# tuple1 = (11,22)
# print(*tuple1)
